const { app, BrowserWindow } = require("electron");
const path = require("path");

// 执行createWindow创建窗口
const createWindow = () => {
  const mainWindow = new BrowserWindow({
    width: 1024,
    height: 768,
    transparent: true,
    frame: true, // 可选，隐藏窗口边框
    title: "贪吃蛇", // 应用标题
    webPreferences: {
      nodeIntegration: true,
    },
  });
  //本地
  mainWindow.loadURL(process.env.VITE_DEV_SERVER_URL);
  //打包
  // mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
};

// Electron 会在初始化后并准备
app.whenReady().then(() => {
  createWindow();
  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on("request-data", (event) => {
  event.reply("response-data", { key: "value" });
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") app.quit();
});
